package com.ssm.exception;

import java.util.Locale;

import org.springframework.web.context.request.RequestAttributes;
import org.springframework.web.context.request.RequestContextHolder;

public class ServiceException extends RuntimeException
{
	private static final long serialVersionUID = 1L;
	private String errorCode;
	private  Locale locale;
	
	public ServiceException(String errorCode) 
	{
		super();
		this.errorCode = errorCode;
	}

	public ServiceException(String errorCode, String message, Throwable cause,
			boolean enableSuppression, boolean writableStackTrace) {
		super(message, cause);
		this.errorCode = errorCode;
	}

	public ServiceException(String errorCode, String message, Throwable cause) {
		super(message, cause);
		this.errorCode = errorCode;
	}

	public ServiceException(String errorCode, String message) {
		super(message);
		this.errorCode = errorCode;
	}

	public ServiceException(String errorCode, Throwable cause) {
		super(cause);
		this.errorCode = errorCode;
	}

	public String getErrorCode() {
		return errorCode;
	}

	public void setErrorCode(String errorCode) {
		this.errorCode = errorCode;
	}

	public Locale getLocale() 
	{
		if(null == locale)
		{
			locale = (Locale)RequestContextHolder.currentRequestAttributes().getAttribute("locale", RequestAttributes.SCOPE_SESSION);
		}
		return locale;
	}

	public void setLocale(Locale locale) 
	{
		this.locale = locale;
	}
	
}
